﻿using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.AspNet.SignalR.Client;
using Hopscotch.Common.Contracts.EnqService;
using Hopscotch.Domain.Enquiry;
using Hopscotch.Domain.Finance;

namespace Hopscotch.Presentation.Communication.HubClients
{
    public class InstrumentHubClient : IInstrumentEnqService
    {
        //todo, cache instrument lookup ids on server and sync updates to client
        //drop cache on disconnect
        private readonly IHubProxy hubProxy;

        public InstrumentHubClient(IHubProxy hubProxy)
        {
            this.hubProxy = hubProxy;
        }

        public Task<Instrument> GetInstrument(int id)
        {
            return hubProxy.Invoke<Instrument>(nameof(IInstrumentEnqService.GetInstrument), id);
        }

        public Task<ICollection<Instrument>> SearchInstrumentAsync(string search)
        {
            var task = hubProxy.Invoke<ICollection<Instrument>>("SearchInstrument", search);
            return task;
        }
    }
}
